<%@page import="java.util.List"%>
<%@page import="database.*"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript" src="/Project1/layui-v2.6.13/layui/layui.js"></script>
		<script type="text/javascript" src="/Project1/js/jquery-1.9.1.min.js"></script>
		<link rel="stylesheet" type="text/css" href="/Project1/layui-v2.6.13/layui/css/layui.css"/>
		<style>
			#limitPage button{
				margin: 0;
			}
			
		</style>
	</head>
	<body>
	<%!int nowpage = 1; %>
	<%
	List<Student> stulist;
	final int num = 3;	
	Object pagenum ;
	if(request.getAttribute("stulist")!=null){
		stulist = (List<Student>)request.getAttribute("stulist");
		pagenum = request.getAttribute("len");
	}
	else{
	stulist = DP.update(Student.class,"select * from student" , null);
	}
	request.setAttribute("stulist", stulist);
	pagenum = stulist.size();
	int pagen = (Integer)pagenum;
	int pagen2 = pagen%num==0?pagen/num:pagen/num+1;
	//System.out.print(pagen2);
	int nu = nowpage<pagen2?num:pagen%num;
	request.setAttribute("pagenum",pagen2);
	request.setAttribute("num", num);
	%>
	<script type="text/javascript">
	var now=<%=nowpage%>;
	</script>
		<div style="padding: 20px;" class="all">
			<div >
				<form class="layui-form" action="<%=request.getContextPath()%>/s" method="post">
				<input type="hidden" name="method" value="select">
					<div class="layui-inline">
						<input type="text" class="layui-input" placeholder="请输入学生姓名">
					</div>
					
					<div class="layui-inline">
						<select name="grade">
							<option value="" selected="selected">年级</option>
							<option value="2019">2019</option>
							<option value="2018">2018</option>
							<option value="2017">2017</option>
							<option value="2016">2016</option>
							<option value="2015">2015</option>
						</select>
					</div>
					<div class="layui-inline">
						<select name="c_id">
							<option value="" selected="selected">学院</option>
							<option value="1">计算机学院</option>
							<option value="2">经济与管理学院</option>
							<option value="3">外国语学院</option>
							<option value="4">建筑工程学院</option>
							<option value="5">机电学院</option>
						</select>
					</div>
					<div class="layui-inline">
						<select name="m_id">
							<option value="" selected="selected">专业</option>
							<option value="1">计算机科学与技术</option>
							<option value="2">电子信息工程</option>
							<option value="3">信息与计算科学</option>
							<option value="4">通信工程</option>
							<option value="5">物联网</option>
						</select>
					</div>
					<input type="submit" value="查询" class="layui-btn">
				</form>
			</div>

			<div style="margin-top:20px;">
				<button class="layui-btn" onclick="openLayer1()">添加</button>
				<button class="layui-btn">导出表格</button>
				<table class="layui-table table">
					<colgroup>
						<col width="100">
						<col width="60">
						<col width="60">
						<col width="200">
						<col width="100">
						<col width="60">
						<col width="250">
						<col width="100">
						<col width="120">
						<col width="100">
						<col width="80">
						<col>
					</colgroup>
					<thead>
						<tr>
							<th>姓名</th>
							<th>性别</th>
							<th>年级</th>
							<th>学院</th>
							<th>专业</th>
							<th>班级</th>
							<th>就业单位</th>
							<th>就业城市</th>
							<th>岗位</th>
							<th>企业类型</th>
							<th>薪资</th>
							<th>操作</th>
						</tr> 
					</thead>
					<tbody class="tbody">
						<c:forEach items="<%=stulist %>" var="st">
							<tr id="${st.id }">
								<td>${st.name}</td>
								<td>${st.sex}</td>
								<td>${st.grade}</td>
								<td>${st.c_id}</td>
								<td>${st.m_id}</td>
								<td>${st.classs}</td>
								<td>${st.company}</td>
								<td>${st.city}</td>
								<td>${st.job}</td>
								<td>${st.type}</td>
								<td>${st.money}</td>
								<td><button class="layui-btn" onclick="openLayer2(${st.id})">更新</button></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<div id="limitPage" align="center">
				<button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green">首页</button>
				<button class="layui-btn layui-btn-sm" onclick="f1()">上一页</button>
				<span class="layui-font-16" >共${pagenum}页</span>
				<button class="layui-btn layui-btn-sm" onclick="f1()">下一页</button>
				<button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green">尾页</button>
			</div>
		</div>
	</body>
	<script>
		function prepage(){
			<%
			System.out.println(nowpage);
			if(nowpage-1>=1)
			nowpage--;
			nu = nowpage<pagen2?num:pagen%num==0?num:pagen%num;
			%>
			for(i=1;i<=<%=pagen %>;i++){
				if(i<<%=1+(nowpage-1)*num+nu%>&&i>=<%=1+(nowpage-1)*num%>){
					$("#"+i).show();
				}
				else{
					$("#"+i).hide();
				}
			}
		}
		function nextpage(){
			<%
			System.out.println(nowpage);
			if(nowpage<=pagen2)
			nowpage++;
			nu = nowpage<pagen2?num:pagen%num==0?num:pagen%num;
			%>
			for(i=1;i<=<%=pagen %>;i++){
				if(i<<%=1+(nowpage-1)*num+nu%>&&i>=<%=1+(nowpage-1)*num%>){
					$("#"+i).show();
				}
				else{
					$("#"+i).hide();
				}
			}
		}
		function f1(){
			<%System.out.println("exe");%>
		}
		layui.use("layer", function(){
			var layer = layui.layer;
			var $ = layui.jquery;
		});
		layer.config({
			  path: '/Project1/layui-v2.6.13/layui' //layer.js所在的目录，可以是绝对目录，也可以是相对目录
			});
		function openLayer1(){
			layer.open({
			  type: 2, 
			  area: ['650px', '500px'],
			  content: 'stuinse.jsp',
			  end: function(){
				  location.reload();
			  }
			});
		}
		
		function openLayer2(id){
			layer.open({
			  type: 2, 
			  area: ['650px', '500px'],
			  content: 'studo.jsp?id='+id,
			  end: function () {
				  location.reload();
			  }
			});
			
		}
	</script>
</html>
